<%@page language="java" pageEncoding="UTF-8"
	contentType="text/html;charset=utf-8"%>
<%@include file="/includes/taglibs.jsp"%>
<%@page import="com.feib.soeasy.util.UserUtil"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title><%=UserUtil.getCurrentMenuItemName() %></title>
	<script type="text/javascript" src="<c:url value='/scripts/jquery/jquery.bgiframe-2.1.2.js'/>"></script>
<script type="text/javascript">
	$(document).ready(function() {

		$('#doQueryBtn').click(function() {
			var qryUserId = $('#qryUser\\.userId').val();
			var qryUserName = $('#qryUser\\.userName').val();
<%if (UserUtil.isBankGroup()) {%>
	var groupNo = $('#qryUser\\.group\\.groupNo').val();
			$('#hidden\\.qryUser\\.group\\.groupNo').val(groupNo);
<%}%>
	$('#hidden\\.qryUser\\.userId').val(qryUserId);
			$('#hidden\\.qryUser\\.userName').val(qryUserName);
			doQueryAction(1);
		});

		$('#doAddBtn').click(function() {
			waitingDialog({});
			$.ajax({
				url : "<c:url value='/ajax/Soez9001.action'/>",
				async : true,
				type : 'POST',
				data : {
					toAjaxAddUser : 'toAjaxAddUser'
				},
				dataType : 'html',
				success : function(data, textStatus, XMLHttpRequest) {
					$("#addResultDiv").html(data);
				},
				error : function(XMLHttpRequest, textStatus, errorThrown) {
					$("#ajaxErrorMessageDiv").html('系統發生錯誤，請聯絡管理員');
					$("#ajaxErrorMessageDiv").dialog("destroy");
					$("#ajaxErrorMessageDiv").dialog({
						title : '系統錯誤',
						width : 600,
						resizable : false,
						modal : true,
						buttons : {
							Ok : function() {
								$(this).dialog("close");
							}
						}
					});
				},
				complete : function(XMLHttpRequest, textStatus) {
					closeWaitingDialog();
				}
			});
		});
<%if (UserUtil.isBankGroup()) {%>
	$('#findGroupNoImg').click(function() {
		var groupNo = $('#qryUser\\.group\\.groupNo').val();
		
		if (null != groupNo && 0 != groupNo.length){
			var tmpGroupNo = parseInt(groupNo,10);
			if(! isNaN(tmpGroupNo)){
				$('#hidden\\.qryGroup\\.groupNo').val(groupNo);
				$('#hidden\\.qryGroup\\.groupName').val('');
				$('#qryGroup\\.groupNo').val(groupNo);
				$('#qryGroup\\.groupName').val('');
			}
			else{
				$('#hidden\\.qryGroup\\.groupNo').val('');
				$('#hidden\\.qryGroup\\.groupName').val(groupNo);
				$('#qryGroup\\.groupNo').val('');
				$('#qryGroup\\.groupName').val(groupNo);
				$("#queryGroupResultDiv").html('');
			}
			
			$("#findGroupDiv" ).dialog({  
				title:'帳單業者查詢' 
				, width: 600
				, resizable: true
				, modal: true
			});
			
			$('#doAjaxQueryGroupsBtn').click();
		}
		else{
			$('#hidden\\.qryGroup\\.groupNo').val('');
			$('#hidden\\.qryGroup\\.groupName').val('');
			$('#qryGroup\\.groupNo').val('');
			$('#qryGroup\\.groupName').val('');
			$("#queryGroupResultDiv").html('');
			$("#findGroupDiv" ).dialog({  
				title:'帳單業者查詢' 
				, width: 600
				, resizable: true
				, modal: true
			});
		}
		});

		$('#doAjaxQueryGroupsBtn').click(function() {
			var groupNo = $('#qryGroup\\.groupNo').val();
			var groupName = $('#qryGroup\\.groupName').val();
			$("#queryGroupResultDiv").html('');

			$('#hidden\\.qryGroup\\.groupNo').val(groupNo);
			$('#hidden\\.qryGroup\\.groupName').val(groupName);
			doQueryGroupAction(1);

		});

		$('#doAjaxCloseGroupsBtn').click(function() {
			$("#findGroupDiv").dialog("destroy");
		});

<%}%>
	//if ( UserUtil.isBankGroup())

		$('#doAjaxModifyBtn').click(function() {
			//alert('Button');
			var userId = $('#qryUser\\.userId').val();
			$("#modifyResultDiv").html('');

			doAjaxModifyAction();

		});

	});//document

	function doAjaxModifyAction() {
		$("#modifyResultDiv").fadeTo("slow", 0.1);

		waitingDialog({});
		$.ajax({
			url : "<c:url value='/ajax/Soez9001.action'/>",
			async : true,
			type : 'POST',
			data : $("#modifyHiddenFrom").serialize(),
			dataType : 'html',
			success : function(data, textStatus, XMLHttpRequest) {
				$("#modifyResultDiv").html(data);
			},
			error : function(XMLHttpRequest, textStatus, errorThrown) {
				$("#ajaxErrorMessageDiv").html('系統發生錯誤，請聯絡管理員');
				$("#ajaxErrorMessageDiv").dialog("destroy");
				$("#ajaxErrorMessageDiv").dialog({
					title : '系統錯誤',
					width : 600,
					resizable : false,
					modal : true,
					buttons : {
						Ok : function() {
							$(this).dialog("close");
						}
					}
				});
			},
			complete : function(XMLHttpRequest, textStatus) {
				closeWaitingDialog();
				$("#modifyResultDiv").fadeTo("slow", 1);

			}
		});

	}

	function doQueryAction(pageNumber) {
		if (null != pageNumber)
			$('#hidden\\.queryResult\\.pageNumber').val(pageNumber);
		$("#queryResultDiv").fadeTo("slow", 0.1);

		waitingDialog({});
		$.ajax({
			url : "<c:url value='/ajax/Soez9001.action'/>",
			async : true,
			type : 'POST',
			data : $("#queryHiddenFrom").serialize(),
			dataType : 'html',
			success : function(data, textStatus, XMLHttpRequest) {
				$("#queryResultDiv").html(data);
			},
			error : function(XMLHttpRequest, textStatus, errorThrown) {
				if (XMLHttpRequest.status == 601) {
		            // reload entire page - this leads to login page
		            window.location="<c:url value='/login.jsp'/>";
		            return ;
				}
				$("#ajaxErrorMessageDiv").html('系統發生錯誤，請聯絡管理員');
				$("#ajaxErrorMessageDiv").dialog("destroy");
				$("#ajaxErrorMessageDiv").dialog({
					title : '系統錯誤',
					width : 600,
					resizable : false,
					modal : true,
					buttons : {
						Ok : function() {
							$(this).dialog("close");
						}
					}
				});
			},
			complete : function(XMLHttpRequest, textStatus) {
				closeWaitingDialog();
				$("#queryResultDiv").fadeTo("slow", 1);

			}
		});
	}
<%if (UserUtil.isBankGroup()) {%>
	function doQueryGroupAction(pageNumber) {
		$('#hidden\\.queryGroupResult\\.pageNumber').val(pageNumber);
		$("#queryGroupResultDiv").fadeTo("slow", 0.1);

		waitingDialog({});
		$.ajax({
			url : "<c:url value='/ajax/Soez9001.action'/>",
			async : true,
			type : 'POST',
			data : $("#queryGroupHiddenFrom").serialize(),
			dataType : 'html',
			success : function(data, textStatus, XMLHttpRequest) {
				$("#queryGroupResultDiv").html(data);
			},
			error : function(XMLHttpRequest, textStatus, errorThrown) {
				$("#ajaxErrorMessageDiv").html('系統發生錯誤，請聯絡管理員');
				$("#ajaxErrorMessageDiv").dialog("destroy");
				$("#ajaxErrorMessageDiv").dialog({
					title : '系統錯誤',
					width : 600,
					resizable : false,
					modal : true,
					buttons : {
						Ok : function() {
							$(this).dialog("close");
						}
					}
				});
			},
			complete : function(XMLHttpRequest, textStatus) {
				if ($.browser.msie && /msie 6\.0/i.test(navigator.userAgent)){
					$("#findGroupDiv" ).dialog( "close" );
					$("#findGroupDiv" ).dialog( "open" );					
				}
				closeWaitingDialog();
				$("#queryGroupResultDiv").fadeTo("slow", 1);
			}
		});
	}

	<%}%>
</script>
</head>

<body>
<div id="mainAreaCT">
<jsp:include page="/includes/path.jsp" /> 
<jsp:include page="/includes/subMenu.jsp" />

<div id="queryFormDiv">
	<stripes:form id="queryUserFrom" beanclass="com.feib.soeasy.action.Soez9001ActionBean" method="post" onsubmit="javascript: return false;">
	
	<table id="queryForm">
		<%	if (UserUtil.isBankGroup()) {%>
		<tr>
			<th>業者代號</th>
			<td>
				<div id="findGroupNoImg">
					<a href="javascript: void(0)" class="btnZoom">查詢</a>
				</div>
				<stripes:text id="qryUser.group.groupNo" name="qryUser.group.groupNo" size="12" maxlength="12" />
				<span id="qryFormatDefinition.group.groupName.span"><c:out value="${actionBean.qryUser.group.groupName }"/></span>
			</td>
		</tr>
		<%
			}
		%>
		<tr>
			<th>使用者ID</th>
			<td>
				<stripes:text id="qryUser.userId" name="qryUser.userId" size="20" maxlength="20" />
			</td>
		</tr>
		<tr>
			<th>姓名</th>
			<td colspan="2">
				<stripes:text id="qryUser.userName" name="qryUser.userName" size="20" maxlength="20" />
			</td>
		</tr>
		<tr>
			<td class="queryFunction" colspan="2">
				<stripes:button id="doQueryBtn" name="doQueryBtn" value="查詢" /> 
				<stripes:button id="doAddBtn" name="doAddBtn" value="新增" />
			</td>
		</tr>
	</table>
	</stripes:form>
</div>
<!-- end #queryForm --> 

<!-- 使用者查詢結果  -->
<div id="queryResultDiv" style="display: none;"></div>

<div id="queryHiddenFormDiv" style="display: none;">
	<stripes:form id="queryHiddenFrom"	beanclass="com.feib.soeasy.action.Soez9001ActionBean" method="post" onsubmit="javascript: return false;">
	<%
		if (UserUtil.isBankGroup()) {
	%>
	<stripes:hidden id="hidden.qryUser.group.groupNo"
		name="qryUser.group.groupNo" />
	<%
		}
	%>
	<stripes:hidden id="hidden.qryUser.userId" name="qryUser.userId" />
	<stripes:hidden id="hidden.qryUser.userName" name="qryUser.userName" />
	<stripes:hidden id="hidden.queryResult.pageNumber" name="queryResult.pageNumber" />
	<input type="hidden" id="hidden.queryResult.sortCriterion" name="queryResult.sortCriterion" value="userId"/>
	<input type="hidden" id="method" name="doAjaxQuery" />
	</stripes:form>
</div>

	<% if (UserUtil.isBankGroup()) {%> <!-- 業者代號 查詢 -->

	<div id="findGroupDiv" style="display: none;">

		<div id="queryGroupDiv">
			<table>
				<tr>
					<th>業者代號</th>
					<td>
						<input id="qryGroup.groupNo" type="text" size="12" maxlength="12" />
					</td>
				</tr>
				<tr>
					<th>名稱</th>
					<td>
						<input id="qryGroup.groupName" type="text" size="20" />
					</td>
				</tr>
				<tr>
					<td colspan="2" class="queryFunction">
						<input type="button" value="查詢" id="doAjaxQueryGroupsBtn" /> 
						<input type="button" value="離開" id="doAjaxCloseGroupsBtn" />
					</td>
				</tr>
			</table>
		</div>
	
		<div id="queryGroupResultDiv" style="display: none;"></div>
	</div>

	<div id="queryGroupHiddenFormDiv" style="display: none;">
		<stripes:form id="queryGroupHiddenFrom" beanclass="com.feib.soeasy.action.Soez9001ActionBean" method="post" onsubmit="javascript: return false;">
			<stripes:hidden id="hidden.qryGroup.groupName" name="qryGroup.groupName" />
			<stripes:hidden id="hidden.qryGroup.groupNo" name="qryGroup.groupNo" />
			<stripes:hidden id="hidden.queryGroupResult.pageNumber" name="queryGroupResult.pageNumber" />
			<input type="hidden" id="method" name="doAjaxQueryGroups" />
		</stripes:form>
	</div>

	<div id="groupNochangedHiddenFromDiv" style="display: none;">
		<stripes:form id="groupNochangedHiddenFrom" beanclass="com.feib.soeasy.action.Soez9001ActionBean" method="post" onsubmit="javascript: return false;">
			<stripes:hidden id="hidden.qryUser.group.groupNo" name="hidden.qryUser.group.groupNo" />
			<input type="hidden" id="method" name="doAjaxGroupNoChange" />
		</stripes:form>
	</div>
	
	<%
		}
	%> <!-- 新增角色畫面  -->
	<div id="addResultDiv" style="display: none;"></div>

		<!-- Message -->
		<div id="ajaxErrorMessageDiv" style="display: none;"></div>
	</div>
</body>
</html>
